$(function () {
    toastr.options.positionClass = 'toast-top-center';
    $("#login").click(function () {
        login();
    });
});


//获取菜单信息
function login() {
    var username = $("#userName").val();
    var password = $("#password").val();

    if(checkIsEmpty(username)){
        toastr.warning('账号不能为空');
        return;
    }
    if(checkIsEmpty(password)){
        toastr.warning('密码不能为空');
        return;
    }

    var param = {
        username: username,
        password: password
    };

    $.ajax({
        type: "post",
        url: "../userInfo/login",
        data: JSON.stringify(param),
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function(result){
            if(result.code == "200"){
                window.location.href="menuInfo.html";
            } else {
                toastr.error(result.message);
            }
        },
        error: function(error){
            toastr.error("系统异常！");
        }
    });


}


function checkIsEmpty(value) {
    if(value==null || value=="" || value==undefined || value.trim().length==0){
        return true;
    }
    return false;
}